#include <cstdio>
#include <algorithm>

using namespace std; 

#define N 101

int a[N][N]; 
int f[N][N]; 

int n, m; 



int main()
{
	int i, j; 
	int ans = 0; 
	
	//freopen("p1387.in", "r", stdin); 	
	scanf("%d %d", &n, &m); 
	for (i=1; i<=n; i++) {
		for (j=1; j<=m; j++) {
			scanf("%d", &a[i][j]); 
		}
	}
	for (i=1; i<=n; i++) {
		for (j=1; j<=m; j++) {
			if (a[i][j]) {
				f[i][j] = min(f[i-1][j-1], min(f[i-1][j], f[i][j-1])) + 1; 
			}
			ans = max(ans, f[i][j]); 
		}
	}

	printf("%d\n", ans); 
	return 0; 
}


